# -*- coding: utf-8 -*-
from django.utils.translation import ugettext_lazy as _
from django.db.models import permalink, signals
from google.appengine.ext import db
from ragendja.dbutils import cleanup_relations
from django.contrib.auth.models import User


class Company(db.Model):
    """A company's profile."""
    name = db.StringProperty(required=True)
    email = db.EmailProperty()
    phone = db.StringProperty()
    location = db.StringProperty()
    description = db.TextProperty()
    url = db.URLProperty()
    twitter = db.StringProperty()
    last_update = db.DateTimeProperty(auto_now=True)
    
    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name = _('Company')
        verbose_name_plural = _('Companies')
        
#    @permalink
#    def get_absolute_url(self):
#        return ('jobs.views.show_company', (), {'key': self.key()})


class Job(db.Model):
    """Open position at a company."""
    company = db.ReferenceProperty(Company, required=True, collection_name='job_set')
    name = db.StringProperty(required=True)
    description = db.TextProperty()
    is_open = db.BooleanProperty(default=True)
    last_update = db.DateTimeProperty(auto_now=True)

    def __unicode__(self):
        return self.name
    
    @permalink
    def get_absolute_url(self):
        return ('jobs.views.show_job', (), {'key': self.key(),
                                                  'name': self.name})


class Employment(db.Model):
    company = db.ReferenceProperty(Company, required=True, collection_name='employee_set')
    employee = db.ReferenceProperty(User, required=True, collection_name='company_set')
    work_email = db.EmailProperty(required=True) # work email for verification
    
    class Meta:
        verbose_name = _('Employment in a company')
        verbose_name_plural = _('Employment in companies')
